package com.insta.achilog.dal;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class RentRequest {

	private Connexion connexion =  new Connexion();

	public void rentBook(String UserId, Integer BookId){
		connexion.ExecuteInsertQuery("INSERT t_louer VALUES null, "+BookId+","+UserId+","+ new java.util.Date().toString() +",0");
	}
	
	public void returnBook(long id){
		connexion.ExecuteUpdateQuery("UPDATE t_louer SET lou_rendu = 1,lou_date="+ new java.util.Date().toString() +" WHERE lou_id = "+ id );
		connexion.ExecuteUpdateQuery("UPDATE t_livre SET liv_nb_exemplaire = liv_nb_exemplaire + 1 WHERE liv_id = (SELECT lou_liv_id From t_louer WHERE lou_id = "+ id+")");
	}
	
	public ResultSet getAllRentForUser(String UserId){

		return connexion.ExecuteSelectQuery("SELECT * FROM t_louer WHERE lou_rendu = 0 and lou_use_id =" + UserId);
					
	}
	
	public ResultSet getAllRent()
	{
		return connexion.ExecuteSelectQuery("SELECT * FROM t_louer WHERE lou_rendu = 0");
	}
	
}
